var self = {

  url: "http://platform.navrise.com:5013",
  // url: "http://192.168.8.50:8089",

  send: function(path, data, back, backThis = null) {

    var request = new XMLHttpRequest();

    request.onreadystatechange = function() {
      if (request.readyState == 4 && (200 <= request.status && request.status < 400)) {

        var result_data = null;

        try {
          var text = request.responseText;
          console.log("------------------------------------");
          console.log(text);
          console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
          result_data = JSON.parse(text);
        } catch (error) {
          console.log(error);
        }

        try {
          if (back && result_data) {
            back(result_data);
          }
        } catch (error) {
          console.log(error);
        }
      }
    };

    var fullPath = self.url + path;

    console.log(fullPath);

    if (data) {
      request.open("POST", fullPath, true);

      if (data instanceof FormData) {
        request.send(data);
      } else {
        var formData = new FormData();
        formData.append("json", JSON.stringify(data));
        request.send(formData);
      }
    } else {
      request.open("GET", fullPath, true);
      request.send();
    }

    console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  },

};

export default self
